home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / coding / 80x86 / code32.lzh / FILE32.ASM < prev    next >
Assembly Source File  |  1993-01-09  |  11KB  |  476 lines

  1. ; OPENFILE              = 1
  2. ; READFILE              = 1
  3. ; WRITEFILE             = 1
  4. ; LSEEKFILE             = 1
  5. ; CREATEFILE            = 1
  6. ; FILESIZE              = 1
  7. ; FILECOPY              = 1
  8. ; DELETEFILE            = 1
  9. ; FINDFILE              = 1
  10.         .386p
  11. code32  segment para public use32
  12.         assume cs:code32, ds:code32, ss:code32
  13.  
  14. include start32.inc
  15.  
  16. public  _filebufloc, _filebuflen
  17. public  _closefile
  18.  
  19. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  20. ; DATA
  21. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  22. _filebufloc     dd      0               ; location must be in low mem
  23. _filebuflen     dw      4000h
  24. oplen           dd      ?
  25.  
  26. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  27. ; CODE
  28. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  29.  
  30. ifdef   CREATEFILE
  31. public  _createfile
  32. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  33. ; Create file
  34. ; In:
  35. ;   EDX -> ASCIIZ filename
  36. ; Out:
  37. ;   CF=1 - Error creating file
  38. ;   CF=0 - File created succesfully
  39. ;     V86R_BX - file handle
  40. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  41. _createfile:
  42.         push ax
  43.         push edx
  44.         add edx,_code32a
  45.         mov ax,dx
  46.         shr edx,4
  47.         and ax,0fh
  48.         mov v86r_dx,ax
  49.         mov v86r_ds,dx
  50.         mov v86r_ax,3c00h
  51.         mov v86r_cx,20h
  52.         mov al,21h
  53.         int 30h
  54.         mov ax,v86r_ax
  55.         mov v86r_bx,ax
  56.         pop edx
  57.         pop ax
  58.         bt word ptr v86r_flags,0
  59.         ret
  60. endif
  61.  
  62. ifdef   OPENFILE
  63. public  _openfile
  64. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  65. ; Open file
  66. ; In:
  67. ;   EDX -> ASCIIZ filename
  68. ; Out:
  69. ;   CF=1 - Error opening file
  70. ;   CF=0 - File opened succesfully
  71. ;     V86R_BX - file handle
  72. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  73. _openfile:
  74.         push ax
  75.         push edx
  76.         add edx,_code32a
  77.         mov ax,dx
  78.         shr edx,4
  79.         and ax,0fh
  80.         mov v86r_dx,ax
  81.         mov v86r_ds,dx
  82.         mov v86r_ax,3d02h
  83.         mov al,21h
  84.         int 30h
  85.         mov ax,v86r_ax
  86.         mov v86r_bx,ax
  87.         pop edx
  88.         pop ax
  89.         bt word ptr v86r_flags,0
  90.         ret
  91. endif
  92.  
  93. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  94. ; Close a file
  95. ; In:
  96. ;   V86R_BX - file handle
  97. ; Out:
  98. ;   None
  99. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  100. _closefile:
  101.         push ax
  102.         mov v86r_ax,3e00h
  103.         mov al,21h
  104.         int 30h
  105.         pop ax
  106.         ret
  107.  
  108. ifdef   DELETEFILE
  109. public  _deletefile
  110. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  111. ; Delete a file
  112. ; In:
  113. ;   EDX -> ASCIIZ filename
  114. ; Out:
  115. ;   CF=1 - Error opening file
  116. ;   CF=0 - File opened succesfully
  117. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  118. _deletefile:
  119.         push ax
  120.         push edx
  121.         add edx,_code32a
  122.         mov ax,dx
  123.         shr edx,4
  124.         and ax,0fh
  125.         mov v86r_dx,ax
  126.         mov v86r_ds,dx
  127.         mov v86r_ah,41h
  128.         mov al,21h
  129.         int 30h
  130.         pop edx
  131.         pop ax
  132.         bt word ptr v86r_flags,0
  133.         ret
  134. endif
  135.  
  136. ifdef   LSEEKFILE
  137. public  _lseekfile
  138. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  139. ; Seek position in file
  140. ; In:
  141. ;   V86R_BX - file handle
  142. ;   EAX - signed offset to move to
  143. ;   BL - from: 0-beginning of file, 1-current location, 2-end of file
  144. ; Out:
  145. ;   CF=1  - Error seeking in file
  146. ;     EAX - ?
  147. ;   CF=0  - Seek fine
  148. ;     EAX - new offset from beginning of file
  149. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  150. _lseekfile:
  151.         mov v86r_ah,42h
  152.         mov v86r_al,bl
  153.         mov v86r_dx,ax
  154.         shr eax,16
  155.         mov v86r_cx,ax
  156.         mov al,21h
  157.         int 30h
  158.         mov ax,v86r_dx
  159.         shl eax,16
  160.         mov ax,v86r_ax
  161.         bt v86r_flags,0
  162.         ret
  163. endif
  164.  
  165. ifdef   FILESIZE
  166. public  _filesize
  167. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  168. ; Get size of file
  169. ; In:
  170. ;   V86R_BX - file handle
  171. ; Out:
  172. ;   CF=1  - Error checking file
  173. ;     EAX - ?
  174. ;   CF=0  - chek fine
  175. ;     EAX - size of file
  176. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  177. _filesize:
  178.         mov v86r_ax,4201h
  179.         xor eax,eax
  180.         mov v86r_cx,ax
  181.         mov v86r_dx,ax
  182.         mov al,21h
  183.         int 30h
  184.         push v86r_dx
  185.         push v86r_ax
  186.         mov v86r_ax,4202h
  187.         xor eax,eax
  188.         mov v86r_cx,ax
  189.         mov v86r_dx,ax
  190.         mov al,21h
  191.         int 30h
  192.         mov ax,v86r_dx
  193.         shl eax,16
  194.         mov ax,v86r_ax
  195.         pop v86r_dx
  196.         pop v86r_cx
  197.         mov v86r_ax,4200h
  198.         push eax
  199.         mov al,21h
  200.         int 30h
  201.         pop eax
  202.         bt v86r_flags,0
  203.         ret
  204. endif
  205.  
  206. ifdef   READFILE
  207. public  _readfile
  208. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  209. ; Read from file
  210. ; In:
  211. ;   V86R_BX - file handle
  212. ;   EDX -> buffer to read to
  213. ;   ECX - number of bytes to read
  214. ; Out:
  215. ;   CF=1 - Error reading file
  216. ;     EAX - ?
  217. ;   CF=0 - Read went fine
  218. ;     EAX - number of bytes read
  219. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  220. _readfile:
  221.         pushad
  222.         xor ebp,ebp
  223.         add edx,_code32a
  224.         lea ebx,[ecx+edx]
  225.         cmp ebx,100000h
  226.         ja readlong
  227.         mov eax,edx
  228.         shr eax,4
  229.         and dx,0fh
  230.         mov v86r_ds,ax
  231.         mov v86r_dx,dx
  232. readl:
  233.         mov eax,0fff0h
  234.         cmp eax,ecx
  235.         jbe readlf1
  236.         mov eax,ecx
  237. readlf1:
  238.         mov v86r_cx,ax
  239.         mov v86r_ax,3f00h
  240.         mov al,21h
  241.         int 30h
  242.         movzx ebx,v86r_ax
  243.         add ebp,ebx
  244.         sub ecx,ebx
  245.         jbe readdone
  246.         or ebx,ebx
  247.         jz readdone
  248.         add v86r_ds,0fffh
  249.         jmp readl
  250. readlong:
  251.         mov edi,edx
  252.         sub edi,_code32a
  253.         mov edx,ecx
  254.         mov eax,_filebufloc
  255.         add eax,_code32a
  256.         mov ebx,eax
  257.         shr eax,4
  258.         and bx,0fh
  259.         mov v86r_ds,ax
  260.         mov v86r_dx,bx
  261.         movzx ebx,_filebuflen
  262. readlongl:
  263.         mov eax,ebx
  264.         cmp eax,edx
  265.         jbe readlonglf1
  266.         mov eax,edx
  267. readlonglf1:
  268.         mov v86r_cx,ax
  269.         mov v86r_ax,3f00h
  270.         mov al,21h
  271.         int 30h
  272.         movzx ecx,v86r_ax
  273.         add ebp,ecx
  274.         mov eax,ecx
  275.         or eax,eax
  276.         jz readdone
  277.         mov esi,_filebufloc
  278.         rep movsb
  279.         sub edx,eax
  280.         ja readlongl
  281. readdone:
  282.         mov oplen,ebp
  283.         popad
  284.         mov eax,oplen
  285.         bt v86r_flags,0
  286.         ret
  287. endif
  288.  
  289. ifdef   WRITEFILE
  290. public  _writefile
  291. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  292. ; Write to file
  293. ; In:
  294. ;   V86R_BX - file handle
  295. ;   EDX -> buffer to write from
  296. ;   ECX - number of bytes to write
  297. ; Out:
  298. ;   CF=1 - Error writing file
  299. ;     EAX - ?
  300. ;   CF=0 - Write went fine
  301. ;     EAX - number of bytes read
  302. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  303. _writefile:
  304.         pushad
  305.         xor ebp,ebp
  306.         add edx,_code32a
  307.         lea ebx,[ecx+edx]
  308.         cmp ebx,100000h
  309.         ja writelong
  310.         mov eax,edx
  311.         shr edx,4
  312.         and ax,0fh
  313.         mov v86r_ds,dx
  314.         mov v86r_dx,ax
  315. writel:
  316.         mov eax,0fff0h
  317.         cmp eax,ecx
  318.         jbe writelf1
  319.         mov eax,ecx
  320. writelf1:
  321.         mov v86r_cx,ax
  322.         mov v86r_ax,4000h
  323.         mov al,21h
  324.         int 30h
  325.         movzx ebx,v86r_ax
  326.         add ebp,ebx
  327.         sub ecx,ebx
  328.         jbe writedone
  329.         add v86r_ds,0fffh
  330.         jmp writel
  331. writelong:
  332.         mov esi,edx
  333.         sub esi,_code32a
  334.         mov edx,ecx
  335.         mov eax,_filebufloc
  336.         add eax,_code32a
  337.         mov ebx,eax
  338.         shr eax,4
  339.         and bx,0fh
  340.         mov v86r_ds,ax
  341.         mov v86r_dx,bx
  342.         movzx ebx,_filebuflen
  343. writelongl:
  344.         mov eax,ebx
  345.         cmp eax,edx
  346.         jbe writelonglf1
  347.         mov eax,edx
  348. writelonglf1:
  349.         mov ecx,eax
  350.         mov edi,_filebufloc
  351.         rep movsb
  352.         mov v86r_cx,ax
  353.         mov v86r_ax,4000h
  354.         mov al,21h
  355.         int 30h
  356.         movzx ecx,v86r_ax
  357.         add ebp,ecx
  358.         sub edx,ecx
  359.         ja writelongl
  360. writedone:
  361.         mov oplen,ebp
  362.         popad
  363.         mov eax,oplen
  364.         bt v86r_flags,0
  365.         ret
  366. endif
  367.  
  368. ifdef   FILECOPY
  369. public  _filecopy
  370. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  371. ; Copy some bytes from one file to another
  372. ; In:
  373. ;   V86R_SI - source file handle
  374. ;   V86R_DI - destination file handle
  375. ;   ECX - number of bytes to copy
  376. ; Out:
  377. ;   CF=1  - Error copying file
  378. ;     EAX - ?
  379. ;   CF=0  - copied fine
  380. ;     EAX - number of bytes copied
  381. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  382. _filecopy:
  383.         pushad
  384.         xor ebp,ebp
  385.         mov edx,_filebufloc
  386.         add edx,_code32a
  387.         mov al,dl
  388.         and ax,0fh
  389.         shr edx,4
  390.         mov v86r_ds,dx
  391.         mov v86r_dx,ax
  392.         movzx ebx,_filebuflen
  393. copylongl:
  394.         mov eax,ebx
  395.         cmp eax,ecx
  396.         jbe copylonglf1
  397.         mov eax,ecx
  398. copylonglf1:
  399.         mov v86r_cx,ax
  400.         mov v86r_ax,3f00h
  401.         mov ax,v86r_si
  402.         mov v86r_bx,ax
  403.         mov al,21h
  404.         int 30h
  405.         mov ax,v86r_ax
  406.         or ax,ax
  407.         jz copydone
  408.         mov v86r_cx,ax
  409.         mov v86r_ax,4000h
  410.         mov ax,v86r_di
  411.         mov v86r_bx,ax
  412.         mov al,21h
  413.         int 30h
  414.         movzx edx,v86r_ax
  415.         add ebp,edx
  416.         sub ecx,edx
  417.         ja copylongl
  418. copydone:
  419.         mov oplen,ebp
  420.         popad
  421.         mov eax,oplen
  422.         bt v86r_flags,0
  423.         ret
  424. endif
  425.  
  426. ifdef   FINDFILE
  427. public  _findfile
  428. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  429. ; Do an AH=4E findfirst
  430. ; In:
  431. ;   AL - type of search: 4E-first, 4F-next
  432. ;   EDX -> 13 byte buffer for filename found
  433. ;   EDI -> search mask
  434. ; Out:
  435. ;   CF=1 - file not found
  436. ;     [EDX] - ?
  437. ;   CF=0 - file found
  438. ;     [EDX] - filename
  439. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  440. _findfile:
  441.         push eax
  442.         push esi
  443.         push edi
  444.         add edi,_code32a
  445.         mov esi,edi
  446.         and esi,0fh
  447.         shr edi,4
  448.         mov v86r_ds,di
  449.         mov v86r_dx,si
  450.         mov v86r_ah,al
  451.         mov v86r_cx,20h
  452.         mov al,21h
  453.         int 30h
  454.         mov esi,_code16a
  455.         sub esi,62h
  456.         mov edi,edx
  457.         mov ax,gs
  458.         mov ds,ax
  459.         movsd
  460.         movsd
  461.         movsd
  462.         movsb
  463.         mov ax,es
  464.         mov ds,ax
  465.         pop edi
  466.         pop esi
  467.         pop eax
  468.         bt v86r_flags,0
  469.         ret
  470. endif
  471.  
  472.  
  473. code32  ends
  474.         end
  475.  
  476.